class Project
  attr_reader :code_index
  
  def initialize(base_dir)
    @base_dir = File.expand_path(base_dir)
    @code_index = CodeIndex.new(self)
  end
  
  def chdir(&block)
    Dir.chdir(@base_dir, &block)
  end
  
  def add_file_ignore_entry(entry)
    File.open(ignore_setting_file, File::WRONLY|File::APPEND) { |file| file << entry << "\n" }
  end
  
  def expand_path(*paths)
    File.join(@base_dir, *paths)
  end
  
  def ignore_setting_file
    create_unless_exist File.join(setting_dir, 'ignores')
  end
  
  private
  def setting_dir
    create_unless_exist(File.join(@base_dir, '.er'), true)
  end
  
  def create_unless_exist(file, is_dir = false)
    unless File.exist?(file)
      is_dir ? FileUtils.mkdir(file) : File.open(file, 'w')
    end
    file
  end
end